# 支持多架构
ARG BASE_REGISTRY=docker.io
FROM ${BASE_REGISTRY}/library/nginx:alpine

# 复制本地构建的静态文件到 Nginx 默认目录
COPY dist/ /usr/share/nginx/html/

# 复制自定义 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 暴露 3000 端口
EXPOSE 3000

# 添加 host.docker.internal 支持（适用于 Linux 环境）
RUN echo 'if [ -z "$(cat /etc/hosts | grep host.docker.internal)" ]; then echo "$(getent hosts host-gateway | awk "{ print \$1 }")  host.docker.internal" >> /etc/hosts; fi' \
    > /docker-entrypoint.d/10-add-host-docker-internal.sh && chmod +x /docker-entrypoint.d/10-add-host-docker-internal.sh

# 创建日志目录并设置权限
RUN mkdir -p /var/log/nginx && chown -R nginx:nginx /var/log/nginx

# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]
